<template>
  <div class="list">
    <div v-for="(item,index) in count" :key="index" class="item" ref="item" :style="itemStyle">
      <span v-for="(itemChild,childIndex) in numArr" :key="childIndex">{{itemChild}}</span>
    </div>
  </div>
</template>
<script>
export default {
  name: "data-v-doubleDealer",
  props: {
    count: {
      type: Number,
      default: 6
    },
    itemStyle: {
      type: Object,
      default: () => {}
    },
    value: {
      type: [Number, String],
      default: 0
    }
  },
  watch: {
    value: function(newVal, oldVal) {
      if (newVal != oldVal) {
        this.change();
      }
    }
  },
  data() {
    return {
      numArr: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ".", ","]
    };
  },

  methods: {
    //数字变动
    change() {
      if (!this.value) return;
      let strArr = this.value.toString().split("");
      let length = strArr.length;
      for (let i = 0; i < this.count - length; i++) {
        strArr.unshift(0);
      }
      let itemHeight = this.$refs.item[0].offsetHeight;
      this.$refs.item.forEach((items, index) => {
        console.log("Number(strArr[index]);",strArr);
        console.log("index;",index);
        
        let ty;
        if (strArr[index] == ".") {
          ty = 10;
        } else if (strArr[index] == ",") {
          ty = 11;
        } else {
          ty = Number(strArr[index]);
        }
        items.style.transform = `translateY(-${ty * itemHeight}px)`;
      });
    }
  },
  mounted() {
    this.change();
  }
};
</script>
<style lang="less">
.list {
  display: flex;
  flex-direction: row;
  align-items: center;
  overflow: hidden;
}
.item {
  display: flex;
  height: 80px;
  width: 50px;
  margin-right: 20px;
  font-size: 40px;
  flex-direction: column;
  transition: all 1s ease-in-out;
  border-radius: 5px;
  span {
    display: inline-block;
    height: 100%;
    width: 100%;
    line-height: 80px;
    text-align: center;
    background: cornflowerblue;
  }
}
</style>